﻿using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
using Loki.Engine;
using Loki.UI.Wpf;

namespace Luna.UI.Wpf
{
    /// <summary>
    /// Interaction pour LunaApp.xaml.
    /// </summary>
    public partial class LunaApp : WpfBootStrapper<MainViewModel>
    {
        private ApplicationModel _ApplicationModel = new ApplicationModel();

        private DataContext _DataContext = new DataContext();

        public LunaApp()
        {
            Theme theme = new Theme("NewTheme", "DevExpress.Xpf.Themes.NewTheme.v13.2");
            theme.AssemblyName = "DevExpress.Xpf.Themes.NewTheme.v13.2";
            Theme.RegisterTheme(theme);

            UIModel.Load += UIModel_Load;
            BootStrapper.Initializing += BootStrapper_Initializing;
            GridControl.AllowInfiniteGridSize = true;
            TreeListControl.AllowInfiniteGridSize = true;
            Exit += LunaApp_Exit;
        }

        private void LunaApp_Exit(object sender, System.Windows.ExitEventArgs e)
        {
            _DataContext.Configuration.CloseCurrentStore();
        }

        public override ObjectModel ApplicationModel
        {
            get
            {
                return _ApplicationModel;
            }
        }

        public override ObjectModel DataModel
        {
            get
            {
                return _DataContext;
            }
        }

        private void BootStrapper_Initializing(object sender, System.EventArgs e)
        {
            Templates.LoadTemplates(Luna.UI.Wpf.ViewInstaller.All);
        }

        private void UIModel_Load(object sender, ContextLoadEventArgs e)
        {
            Luna.UI.ViewModelInstaller.All.Install(e.ObjectContext);
        }
    }
}